package com.agentpad;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class HousePictureAdapter extends BaseAdapter{
	private Context mContext; 
	private List<Uri> pictures = new ArrayList<Uri>();
	
	public HousePictureAdapter(Context c) {        
		mContext = c;    
	}    
	
	public int getCount() {        
		return pictures.size();    
	}    
	
	public Object getItem(int position) {        
		return null;    
	}    
	
	public long getItemId(int position) {        
		return 0;    
	}    
	
	// create a new ImageView for each item referenced by the Adapter    
	public View getView(int position, View convertView, ViewGroup parent) {        
		ImageView imageView;        
		if (convertView == null) {  
			// if it's not recycled, initialize some attributes            
			imageView = new ImageView(mContext);            
			imageView.setLayoutParams(new GridView.LayoutParams(85, 85));            
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);            
			imageView.setPadding(8, 8, 8, 8);        
		} else {            
			imageView = (ImageView) convertView;        
		}        
		
		imageView.setImageURI(pictures.get(position));
		return imageView;    
	} 
	
	public void addPic(String picUri)
	{
		String pics[] = picUri.split(";");
		for(int i = 0; i < pics.length; i ++)
		{
			String pic = pics[i].trim();
			if(pic != null && !"".equals(pic))
				addPic(Uri.parse(pic));
		}
	}
	
	public void addPic(Uri pic)
	{
		pictures.add(pic);
	}
	
	public void clear()
	{
		pictures.clear();
	}
}
